home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1669 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: realloc->free?
  5. Date: Tue, 16 Jan 1996 03:20:10 GMT
  6. Organization: Netcom
  7. Message-ID: <30fb133c.1128448@nntp.ix.netcom.com>
  8. References: <4daa2e$oh5@axe.netdoor.com> <4df2ud$706@oxy.rust.net>
  9. NNTP-Posting-Host: ix-dc7-26.ix.netcom.com
  10. X-NETCOM-Date: Mon Jan 15  7:20:10 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. ebennett@rust.net wrote:
  14.  
  15. |>esargent@netdoor.com (Eric Sargent) wrote:
  16. |>
  17. |>
  18. |>
  19. |>>    Now let's say realloc had to move the data so a != b.  Does
  20. realloc
  21. |>>free the memory previously pointed to by a or should it be
  22. explicitly
  23. |>>freed if realloc returns a new location?  I checked the FAQ, but
  24. there
  25. |>>was nothing specific about realloc.  Thanks for any information.
  26. |>
  27. |>realloc() will free the old block.  It is perfectly legal to say
  28. |>
  29. |>  a = realloc(a, newsize);
  30. |>
  31. |>No memory loss should occur from this.
  32.  
  33. What if realloc() fails?  This will assign NULL to a and the old value
  34. will be lost unless it's been stored in some other variable.
  35.  
  36.  
  37. Michael M Rubenstein
  38.